package com.macro.mall.portal.service.impl;

import com.macro.mall.mapper.BmsFeedbackPicMapper;
import com.macro.mall.model.BmsFeedbackPic;
import com.macro.mall.model.BmsFeedbackPicExample;
import com.macro.mall.portal.service.BmsFeedBackPicService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 商品属性管理Service实现类
 * Created by macro on 2018/4/26.
 */
@Service
public class BmsFeedBackPicServiceImpl implements BmsFeedBackPicService {

    @Autowired
    private BmsFeedbackPicMapper bmsFeedbackPicMapper;


    @Override
    public int deleteByFeedBackId(Long id) {

        BmsFeedbackPicExample example = new BmsFeedbackPicExample();
        BmsFeedbackPicExample.Criteria criteria = example.createCriteria();
        criteria.andBmsFeedbackIdEqualTo(id);
        return bmsFeedbackPicMapper.deleteByExample(example);
    }

    @Override
    public int create(Long feedbackId,List<String> picList) {
        if (Objects.isNull(feedbackId) || CollectionUtils.isEmpty(picList)) {
            return 0;
        }
        for (String pic : picList) {
            BmsFeedbackPic bmsFeedbackPic = new BmsFeedbackPic();
            bmsFeedbackPic.setBmsFeedbackId(feedbackId);
            bmsFeedbackPic.setPic(pic);
            bmsFeedbackPicMapper.insertSelective(bmsFeedbackPic);
        }
        return 0;
    }

    @Override
    public List<BmsFeedbackPic> selectByExample(BmsFeedbackPicExample bmsFeedbackPicExample) {
        return bmsFeedbackPicMapper.selectByExample(bmsFeedbackPicExample);
    }
}
